<?php
session_start();
require_once __DIR__.'/../../utils/checkTokenUtils.php';
require_once __DIR__.'/../../utils/MysqlDBUtils.php';
use utils\MysqlDBUtils;

if ($_SERVER['REQUEST_METHOD']!=='POST'){
    http_response_code(405);
    die('错误：仅支持POST请求');
}

$dbUtil=new MysqlDBUtils();

$id=isset($_POST['id'])? intval($_POST['id']) : 0;

if (empty($id)){
    http_response_code(400);
    die('错误：分类ID不能为空');
}
$deleteSql="DELETE FROM book_category WHERE id=$id";
$result=$dbUtil->prepareQuery($deleteSql);

if ($result !== false){
    $_SESSION['success_message']='分类删除成功';
}else{
    $_SESSION['error_message']='错误：数据库删除失败';
}
header("Location: Categories.php");
exit;